import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 21626
 * Date: 2024-10-27
 * Time: 2:49
 */

public class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i < tokens.length;i++){
            String tmp = tokens[i];
            if(!isOpertor(tmp)){
                stack.push(Integer.valueOf(tmp));
            }else{
                Integer val2 = stack.pop();
                Integer val1 = stack.pop();
                switch(tmp){
                    case "+" :
                        stack.push(val1 + val2);
                        break;
                    case "-" :
                        stack.push(val1 - val2);
                        break;
                    case "*" :
                        stack.push(val1 * val2);
                        break;
                    case "/" :
                        stack.push(val1 / val2);
                        break;
                }
            }

        }
        return stack.pop();
    }
    private boolean isOpertor(String tmp){
        if(tmp.equals("+") || tmp.equals("-") || tmp.equals("*") || tmp.equals("/")){
            return true;
        }
        return false;
    }
}
